package com.example.bomc.dao;

import com.example.bomc.model.Query;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QueryDAO {
    String TABLE_NAME = "query";
    String INSET_FIELDS = " choose, trouble, user, time ,reply,tag,assess,fixname";

    /**
     *  提交问题
    * */
    @Insert({"insert into ", TABLE_NAME, "(", INSET_FIELDS,
            ") values (#{choose},#{trouble},#{user},#{time},#{reply},#{tag},#{assess},#{fixname})"})
    void addQuery(Query query);

    /**
     *  查询是否重复提交问题
     * */
    @Select({"select ", INSET_FIELDS, " from ", TABLE_NAME, " where trouble=#{trouble} and user=#{user}"})
    List<Query> selSameQuery(@Param("trouble") String trouble, @Param("user") String user);

    /**
     *  查询问题
     * */
    @Select({"select ", INSET_FIELDS, " from ", TABLE_NAME, " where trouble=#{trouble}"})
    List<Query> selQuery(@Param("trouble") String trouble);

    /**
     *  历史记录
     * */
    @Select({"select ", INSET_FIELDS, " from ", TABLE_NAME, " where user=#{user}"})
    List<Query> selHistory(@Param("user") String user);

    /**
     *  反馈
     * */
    @Update({"update",TABLE_NAME,"set assess =#{assess} where id=#{id} "})
    void addAssess(@Param("assess") String  assess, @Param("id") int id);
    /**
     *  查询id
     * */
    @Select({"select id  from ", TABLE_NAME, " where trouble=#{trouble} and user=#{user}"})
   Query selectIdByTroubleAndUser(@Param("trouble") String trouble, @Param("user") String user);


}
